//
//  WFFarmEditFooterView.m
//  WisdomFarm
//
//  Created by sky on 2017/11/25.
//  Copyright © 2017年 sky. All rights reserved.
//

#import "WFButtonTableFooterView.h"

@implementation WFButtonTableFooterView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        _saveButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_saveButton];
        _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_deleteButton];
        
        [_saveButton setTitle:@"保存" forState: UIControlStateNormal];
        [_saveButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _saveButton.titleLabel.font = SCFont(16);
        _saveButton.backgroundColor = [UIColor themeColor];
        _saveButton.layer.cornerRadius = 2;

        [_deleteButton setTitle:@"删除" forState: UIControlStateNormal];
        [_deleteButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _deleteButton.titleLabel.font = SCFont(16);
        _deleteButton.backgroundColor = [UIColor standardRedColor];
        _deleteButton.layer.cornerRadius = 2;
        
        self.deleteButton.hidden = YES;
        [self.deleteButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        }];
        self.saveButton.backgroundColor = [UIColor standardRedColor];
        [self.saveButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.right.insets(UIEdgeInsetsMake(5, 12, 5, 12));
            make.height.mas_equalTo(40);
            make.centerY.offset(0);
        }];

    }
    return self;
}

- (void)setCanDelete:(BOOL)canDelete {
    _canDelete = canDelete;
    self.deleteButton.hidden = !canDelete;
    if (canDelete) {
        self.saveButton.backgroundColor = [UIColor themeColor];
        [self.saveButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.insets(UIEdgeInsetsMake(5, 12, 5, 0));
            make.right.equalTo(self.deleteButton.mas_left).offset(-5);
            make.width.mas_equalTo(self.deleteButton.mas_width);
            make.centerY.offset(0);
            make.height.mas_equalTo(40);
        }];
        [self.deleteButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.insets(UIEdgeInsetsMake(5, 0, 5, 12));
            make.centerY.offset(0);
            make.height.mas_equalTo(40);
        }];
    } else {
        [self.deleteButton mas_remakeConstraints:^(MASConstraintMaker *make) {
        }];
        self.saveButton.backgroundColor = [UIColor standardRedColor];
        [self.saveButton mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.right.insets(UIEdgeInsetsMake(5, 12, 5, 12));
            make.height.mas_equalTo(40);
            make.centerY.offset(0);
        }];
    }
}

@end
